package com.wlhse.util;

import com.wlhse.dao.ProblemFactorDao;
import com.wlhse.dao.TaskAndProcessDao;
import com.wlhse.entity.ProblemFactorPojo;
import com.wlhse.entity.TaskAndProcessPojo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DefaultUtil {
    @Resource
    private ProblemFactorDao problemFactorDao;

    @Resource
    private ProblemFactorPojo problemFactorPojo;

    @Resource
    private TaskAndProcessDao taskAndProcessDao;

    @Resource
    private TaskAndProcessPojo taskAndProcessPojo;

    public void setProblemFactor(String problemFactorCode) {
        String defaultCode = problemFactorCode + "00";
        if (problemFactorDao.selectProblemFactorCode(defaultCode) == 0) {
            problemFactorPojo.setProblemFactorName("其它");
            problemFactorPojo.setProblemFactorCode(defaultCode);
            problemFactorPojo.setProblemFactorHash(HashUtil.hash(problemFactorPojo.getProblemFactorCode() + problemFactorPojo.getProblemFactorName()));
            problemFactorDao.insertSingle(problemFactorPojo);
        }
    }

    public void setTaskAndProcess(String taskAndProcessCode) {
        String defaultCode = taskAndProcessCode + "00";
        if (taskAndProcessDao.getTaskAndProcessCount(defaultCode) == 0) {
            taskAndProcessPojo.setStatus("启用");
            taskAndProcessPojo.setTaskAndProcessCode(defaultCode);
            taskAndProcessPojo.setTaskAndProcessName("其它");
        }
    }

}
